function Info(layui) {
    this.table = layui.table;
    this.$ = layui.$;
    this.func = layui.func;
    this.admin = layui.admin;
    this.tableId = "info";
    var that = this;

    /**
     * 档案资料信息表管理
     */

    /**
     * 初始化表格的列
     */
    this.initColumn = function () {
        return [[
            {fixed: 'left', width: 80, type: 'radio'},
            {field: 'id',width:80, hide: true, title: 'id'},
            {field: 'xh',width:80, fixed: 'left', sort: true, title: '序号'},
            {field: 'wh',width:80, sort: true, title: '文号'},
            {field: 'zlmc',width:160, title: '资料名称'},
            {field: 'zllx',   width:120, title: '资料类型',templet:'#zllx'},
            {field: 'qspzh',  width:120, title: '起始凭证号'},
            {field: 'jspzh',  width:120, title: '结束凭证号'},
            {field: 'qsym',   width:120, title: '起始页码'},
            {field: 'jzym',   width:120, title: '截止页码'},
            {field: 'nd',     width:120, title: '年度'},
            {field: 'sfyx',   width:120, title: '是否有效',templet:'#sfyx'},
            {field: 'beiz',   width:200, title: '备注'},
            // {field: 'daid',   width:120, title: '档案id'},
            {fixed: 'right', width: 120, align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };


    // 渲染表格
    this.tableResult = this.table.render({
        elem: '#' + this.tableId,
        page: false,
        height: "500",
        data: [],
        toolbar: '#toolbar',
        defaultToolbar: [],
        cellMinWidth: 100,
        cols: this.initColumn(),
        done:function (res,cur,data) {
            if (cur == 1) {
                var selector = ".layui-table-view[lay-id='"+that.tableId+"'] .layui-table-body tr[data-index=0] .layui-form-radio";
                that.$(selector).click();
            }
        }
    });

    this.setParentId = function (id) {
        this.parentId = id;
        this.table.reload(this.tableId, {
            url: Feng.ctxPath + '/archiveMaterials/list',
            where: {'daid': id}
        });
        this.callback&&this.callback(0,{id:-1});
    }


    /**
     * 弹出添加对话框
     */
    this.openAddDlg = function () {
        if(!(this.parentId && this.parentId !=-1)){
            Feng.error("请选择所属档案");
            return;
        }

        this.func.open({
            height: 600,
            width: 600,
            title: '添加档案资料',
            content: Feng.ctxPath + '/archiveMaterials/add?parentId=' + that.parentId,
            tableId: that.tableId
        });
    };


    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    this.openEditDlg = function (data) {
        // window.location.href = Feng.ctxPath + '/archiveMaterials/edit?id=' + data.id;
        this.func.open({
            height: 600,
            width: 600,
            title: '编辑档案资料',
            content: Feng.ctxPath + '/archiveMaterials/edit?id=' + data.id,
            tableId: that.tableId
        });
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    this.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/archiveMaterials/delete", function (data) {
                Feng.success("删除成功!");
                that.table.reload(that.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };


    // 工具条点击事件
    this.table.on('toolbar(' + this.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'add') {
            that.openAddDlg();
        }
    });


    // 工具条点击事件
    this.table.on('tool(' + this.tableId + ')', function (obj) {
        var layEvent = obj.event;
        var data = obj.data;
        if (layEvent === 'edit') {
            that.openEditDlg(data);
        } else if (layEvent === 'delete') {
            that.onDeleteItem(data);
        }
    });

    this.callback = null;
    this.setItemSelect = function (callback) {
        this.callback = callback;
        this.table.on('row(' + this.tableId + ')', function (obj) {
            callback(Feng.index(obj), obj.data);
        })
    }


}


